package com.huiminpay.merchant.service;

import java.util.ArrayList;

/**
 * @Author: HWW
 * @Date: 2021/8/2715:10
 * @Desc: 排序练习
 */
public class testSort {


    public static void main(String[] args) {

        int arr[] = {1,8,3,7,2,9,0,};
        bubbleSort(arr);

    }



    public static void testSortMax2Min(int arr[]){
        for (int i = 0; i < arr.length -1; i++) {
            for (int j = 0; j < arr.length - 1 -i; j++) {
                int tmp = arr[j];
                if(arr[j]>arr[j+1]){
                    arr[j]=arr[j+1];
                    arr[j]=tmp;
                }
            }
        }

    }




    /**
     * 冒泡排序-从小到大排序
     * @param arr
     */
    public static   void bubbleSort(int arr[]) {

        System.out.print("排序前：");
        for (int i : arr) {
            System.out.print(i+" ");
        }
        System.out.println(" ");
        
        for (int i = 0; i < arr.length - 1; i++) {

            for (int j = 0; j < arr.length - 1 - i; j++) {

                if (arr[j] > arr[j +1]) {
                    int temp = arr[j];

                    arr[j] = arr[j + 1];

                    arr[j + 1] = temp;
                }
            }
        }

        System.out.print("排序后：");
        for (int i : arr) {
            System.out.print(i+" ");
        }


    }
}
